package com.sihai.ehr.web.action.contract;

import com.sihai.core.LimitedList;
import com.sihai.core.beans.BeanInject;
import com.sihai.ehr.model.biz.*;
import com.sihai.ehr.model.sys.AuditStatus;
import com.sihai.ehr.service.ContractService;
import com.sihai.ehr.service.DutyService;
import com.sihai.ehr.service.EmployeeService;
import com.sihai.ehr.utils.DateUtil;
import com.sihai.ehr.web.action.EHRAction;
import com.sihai.ehr.web.pojo.ContractSignPojo;
import com.sihai.ehr.web.pojo.ContractSignPojo2;
import org.apache.commons.lang.xwork.StringUtils;
import org.apache.struts2.ServletActionContext;
import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Result;
import org.apache.struts2.convention.annotation.Results;

import java.util.List;

/**
 * 合同签订审核Action
 */
@Results({@Result(name = "main", location = "contract_main.jsp"),
        @Result(name = "list", location = "contract_sign_audit_list.jsp"),
        @Result(name = "detail", location = "contract_sign_audit.jsp"),
        @Result(name = "common_audit", location = "/WEB-INF/pages/common/common_audit.jsp"),
        @Result(name = "sign_create", location = "contract_sign_create.jsp"),
        @Result(name = "sign_create_zz", location = "contract_sign_create_zz.jsp"),
        @Result(name = "sign_create_rt", location = "contract_sign_create_rt.jsp"),
        @Result(name = "sign_create_rtt", location = "contract_sign_create_rtt.jsp")
})
public class AuditAction extends EHRAction {

    @BeanInject
    private ContractService contractService;
    @BeanInject
    private EmployeeService employeeService;
    @BeanInject
    private DutyService dutyService;

    private List<List<ContractSignAuditing>> audits;

    private LimitedList<ContractSignPojo> contractSignPojos;
    private LimitedList<ContractSignPojo2> pojo2s;

    private ContractSignPojo signPojo;
    private ContractSignPojo2 signPojo2;

    private ContractSign contractSign;
    private ContractSignZz contractSignZz;
    private ContractSignRt contractSignRt;
    private ContractSignRtt contractSignRtt;

    private String totalTime;

    private Duty duty;

    private EmployeeinfoBase baseinfo;

    private Long id;//contractSign id
    private Integer state;//合同状态

    private ContractVersion version;

    private String type;

    private Long reSignContractSignId; //续签合同ID
    private Long reSignContractSignZzId;//续签合同ID
    private Long reSignContractSignRtId;//退休人员合同ID
    private Long reSignContractSignRttId;//退休人员合同ID
    
    private boolean result;

    //合同签订审核
    @Override
    @Action(value = "/contract/conAudit")
    public String execute() throws Exception {
        type = "audit";
        this.listAction = "/contract/conAudit_list.xhtml?type=audit";
        this.listTitle = "合同签订审核";

        return "main";
    }

    //合同人员查看
    @Action(value = "/contract/contPersonView")
    public String contPersonView() throws Exception {
        type = "view";
        this.listAction = "/contract/conAudit_list.xhtml?type=view";
        this.listTitle = "合同人员查看";

        return "main";
    }

    //合同签订审核列表

    @Action(value = "/contract/conAudit_list")
    public String list() throws Exception {
        pojo2s = contractService.findForContractSignAudit(organizationId, type, createLimit(), createSorter());

        //分页
        this.paging(pojo2s);
        this.setPageUrl("contract/conAudit_list.xhtml");

        return "list";
    }

    //跳转到合同审核详细页面
    @Action(value = "/contract/audit_detail")
    public String auditDetail() throws Exception {
    	//added by henry #start ---> add the parameter employeeId
        if (getParameter("employeeId") != null && !getParameter("employeeId").isEmpty()) {
            try {

                signPojo = contractService.findForContractSignAuditByEmpolyeeId(organizationId, Long.parseLong(getParameter("employeeId")));
            } catch (Exception ex) {
                ex.printStackTrace();
            }
        }
        //added by henry #end
        signPojo2 = contractService.findForContractSignAuditByEmpolyeeId2(organizationId, signPojo.getWork().getId());
        if(signPojo2 != null){
            List<ContractVersion> vs = signPojo2.getVersions();
            if(vs != null && !vs.isEmpty()){
                for(ContractVersion v : vs){
                    EmployeeinfoBase employee = null;
                    if(v.getSign() != null){
                        employee = v.getSign().getEmployeeinfoBase();
                    }
                    if(v.getSignZz() != null){
                        employee = v.getSignZz().getEmployeeinfoBase();
                    }
                    
                    //@{ added by henry
                    if(v.getSignRt() != null){
                        employee = v.getSignRt().getEmployeeinfoBase();
                    }
                    if(v.getSignRtt() != null){
                        employee = v.getSignRtt().getEmployeeinfoBase();
                    }
                    // @}
                    if(employee != null && v.getAudits() != null && v.getAudits().size() > 0){
                        //检查当前登录用户是否可以审核当前结点
                        checkCanAudit(employee, v.getAudits().get(v.getAudits().size() - 1));
                        v.setCanAudit(canAudit);
                    }
                }
            }
        }
        currentAuditType = AuditType.audit_contract_sign.toString();
        return "detail";
    }

    //跳转到合同审核详细页面
    @Action(value = "/contract/audit_detail_bak")
    public String auditDetail_bak() throws Exception {
        //added by henry #start ---> add the parameter employeeId
        if (getParameter("employeeId") != null && !getParameter("employeeId").isEmpty()) {
            try {

                signPojo = contractService.findForContractSignAuditByEmpolyeeId(organizationId, Long.parseLong(getParameter("employeeId")));
            } catch (Exception ex) {
                ex.printStackTrace();
            }
        }
        //added by henry #end
        if (signPojo == null || signPojo.getWork() == null || signPojo.getWork().getId() == null) {
            return list();
        }
        EmployeeinfoWork work = employeeService.getEmployeeinfoWork(signPojo.getWork().getId());
        if (work == null) {
            return list();
        }
        signPojo.setWork(work);

        LimitedList<ContractVersion> versions = contractService.findVersionsByDutyId(work.getDuty().getId(), null, null);
        signPojo.setVersions(versions);

        if (signPojo.getContractSignId() != null && signPojo.getContractSignId() > 0) {
            ContractSign sign = contractService.getContractSign(signPojo.getContractSignId());
            signPojo.setSign(sign);
            long contractSignId = signPojo.getSign().getId();
            contractSign = contractService.getContractSign(contractSignId);
            audits = contractService.findContractSignAuditing("sign", contractSignId);
            if (audits == null || audits.isEmpty()) {
                contractService.saveContractSignAuditingProcess("sign", contractSignId);
                audits = contractService.findContractSignAuditing("sign", contractSignId);
            }
            //检查当前登录用户是否可以审核当前结点
            if(contractSign.getEmployeeinfoBase() != null && audits != null && !audits.isEmpty()){
                checkCanAudit(contractSign.getEmployeeinfoBase(), audits.get(audits.size()-1));
            }
            currentAuditType = AuditType.audit_contract_sign.toString();
        }

        return "detail";
    }


    @Action(value = "/contract/sign_auditing")
    public String findContractAuditing() throws Exception {
        if(contractSign != null && contractSign.getId() != null && contractSign.getId() > 0){
            audits = contractService.findContractSignAuditing("sign", contractSign.getId());
            if (audits == null || audits.isEmpty()) {
                contractService.saveContractSignAuditingProcess("sign", contractSign.getId());
                audits = contractService.findContractSignAuditing("sign", contractSign.getId());
            }
        }
        if(contractSignZz != null && contractSignZz.getId() != null && contractSignZz.getId() > 0){
            audits = contractService.findContractSignAuditing("signZz", contractSignZz.getId());
            if (audits == null || audits.isEmpty()) {
                contractService.saveContractSignAuditingProcess("signZz", contractSignZz.getId());
                audits = contractService.findContractSignAuditing("signZz", contractSignZz.getId());
            }
        }
        // added by henry @{
        if(contractSignRt != null && contractSignRt.getId() != null && contractSignRt.getId() > 0){
            audits = contractService.findContractSignAuditing("signRt", contractSignRt.getId());
            if (audits == null || audits.isEmpty()) {
                contractService.saveContractSignAuditingProcess("signRt", contractSignRt.getId());
                audits = contractService.findContractSignAuditing("signRt", contractSignRt.getId());
            }
        }
        if(contractSignRtt != null && contractSignRtt.getId() != null && contractSignRtt.getId() > 0){
            audits = contractService.findContractSignAuditing("signRtt", contractSignRtt.getId());
            if (audits == null || audits.isEmpty()) {
                contractService.saveContractSignAuditingProcess("signRtt", contractSignRtt.getId());
                audits = contractService.findContractSignAuditing("signRtt", contractSignRtt.getId());
            }
        }
        // added by henry @}
        //检查当前登录用户是否可以审核当前结点
        if(contractSign.getEmployeeinfoBase() != null && audits != null && !audits.isEmpty()){
            checkCanAudit(contractSign.getEmployeeinfoBase(), audits.get(audits.size()-1));
        }
        return "common_audit";
    }

    //确认签订合同
    @Action(value = "/ajax/contact_sign", results = {@Result(name = "success", type = "json", params = {"root", "result"})})
    public String sign() throws Exception {
        if (contractSign == null || contractSign.getId() == null || contractSign.getId() <= 0) {
            return SUCCESS;
        }
        contractSign = contractService.getContractSign(contractSign.getId());
        contractSign.setState(4);
        contractService.saveSignContract(null, contractSign);
        result = true;
        return SUCCESS;
    }
    //确认签订合同
    @Action(value = "/ajax/contact_signZz", results = {@Result(name = "success", type = "json", params = {"root", "result"})})
    public String signZz() throws Exception {
        if (contractSignZz == null || contractSignZz.getId() == null || contractSignZz.getId() <= 0) {
            return SUCCESS;
        }
        contractSignZz = contractService.getContractSignZz(contractSignZz.getId());
        contractSignZz.setState(4);
        contractService.saveSignContract(null, contractSignZz);
        result = true;
        return SUCCESS;
    }
    
    //确认签订合同
    @Action(value = "/ajax/contact_signRt", results = {@Result(name = "success", type = "json", params = {"root", "result"})})
    public String signRt() throws Exception {
        if (contractSignRt == null || contractSignRt.getId() == null || contractSignRt.getId() <= 0) {
            return SUCCESS;
        }
        contractSignRt = contractService.getContractSignRt(contractSignRt.getId());
        contractSignRt.setState(4);
        contractService.saveSignContract(null, contractSignRt);
        result = true;
        return SUCCESS;
    }
    
    //确认签订合同
    @Action(value = "/ajax/contact_signRtt", results = {@Result(name = "success", type = "json", params = {"root", "result"})})
    public String signRtt() throws Exception {
        if (contractSignRtt == null || contractSignRtt.getId() == null || contractSignRtt.getId() <= 0) {
            return SUCCESS;
        }
        contractSignRtt = contractService.getContractSignRtt(contractSignRtt.getId());
        contractSignRtt.setState(4);
        contractService.saveSignContract(null, contractSignRtt);
        result = true;
        return SUCCESS;
    }

        @Action(value = "/contract/sign_contract")
    public String buildContractDetail() throws Exception {
        if (getParameter("dutyId") == null || getParameter("employeeId") == null) {
            return ERROR;
        }

        if (signPojo == null) {
            signPojo = new ContractSignPojo();
        }
        EmployeeinfoBase mEmployeeinfoBase = employeeService.getEmployeeinfoBase(Long.parseLong(getParameter("employeeId")));
        if (mEmployeeinfoBase != null) {
            EmployeeinfoWork mEmployeeinfoWork = new EmployeeinfoWork();
            mEmployeeinfoWork.setBaseId(mEmployeeinfoBase);
            signPojo.setWork(mEmployeeinfoWork);
        } else {
            return list();
        }

        LimitedList<ContractVersion> versions = contractService.findVersionsByDutyId(Long.parseLong(getParameter("dutyId")), null, null);
        signPojo.setVersions(versions);

        //检测签约合同

//        if (signPojo.getContractSignId() != null && signPojo.getContractSignId() > 0) {
//            ContractSign sign = contractService.getContractSign(signPojo.getContractSignId());
//            signPojo.setSign(sign);
//        }

        return "detail";
    }

    //跳转到合同生成/修改页面
    @Action(value = "/contract/sign_create")
    public String gotoCreate() throws Exception {
        if(version == null || version.getId() == null || version.getId() <= 0){
            return "error";
        }
        version = contractService.getVersion(version.getId());
        if(StringUtils.equals("contract_template1", version.getContractTemplate())){
        	
        }else if(StringUtils.equals("contract_template2", version.getContractTemplate())){
        	
        }else if(StringUtils.equals("contract_template3", version.getContractTemplate())){
        	
        }

        duty = dutyService.get(Long.parseLong(getParameter("did")));
        if(contractSign == null && contractSignZz == null && contractSignRt == null && contractSignRtt == null){
            baseinfo = employeeService.getEmployeeinfoBase(Long.parseLong(getParameter("baseId")));
            // added by henry @{
            if(StringUtils.equals("contract_template1", version.getContractTemplate())){
	        	contractSign = new ContractSign();
	        	contractSign.setCompanyName("厦门乔盛服装饰品有限公司");
	        	contractSign.setCompHabitude("外商独资");
	        	contractSign.setPrincipal("李丁山");
	        	contractSign.setComAddress("厦门市集美北区英瑶路175号");
            }else if(StringUtils.equals("contract_template2", version.getContractTemplate())){
            	contractSignZz = new ContractSignZz();
            	contractSignZz.setCompanyName("漳州通茂服装饰品有限公司");
//            	contractSignZz.setCompHabitude("外商独资");
            	contractSignZz.setPrincipal("李奕奇");
            	contractSignZz.setComAddress("龙海市东园工业区");
            }
            // added by henry @}
        }else{
            if (contractSign != null && contractSign.getId() != null) {
                contractSign = contractService.getContractSign(contractSign.getId());
                baseinfo = contractSign.getEmployeeinfoBase();
                if (contractSign.getBeginDate() != null){
                    contractSign.setBeginDateStr(DateUtil.getStrByDate(contractSign.getBeginDate(), "yyyy-MM-dd"));
                }
                if (contractSign.getEndDate() != null){
                    contractSign.setEndDateStr(DateUtil.getStrByDate(contractSign.getEndDate(), "yyyy-MM-dd"));
                }
            }

            if (contractSignZz != null && contractSignZz.getId() != null) {
                contractSignZz = contractService.getContractSignZz(contractSignZz.getId());
                baseinfo = contractSignZz.getEmployeeinfoBase();
                if (contractSignZz.getBeginDate() != null){
                    contractSignZz.setBeginDateStr(DateUtil.getStrByDate(contractSignZz.getBeginDate(), "yyyy-MM-dd"));
                }
                if (contractSignZz.getEndDate() != null){
                    contractSignZz.setEndDateStr(DateUtil.getStrByDate(contractSignZz.getEndDate(), "yyyy-MM-dd"));
                }
                if(contractSignZz.getSyqStartDate() != null){
                    contractSignZz.setSyqStartDateStr(DateUtil.getStrByDate(contractSignZz.getSyqStartDate(), "yyyy-MM-dd"));
                }
                if(contractSignZz.getSyqEndDate() != null){
                    contractSignZz.setSyqEndDateStr(DateUtil.getStrByDate(contractSignZz.getSyqEndDate(), "yyyy-MM-dd"));
                }
            }

            // added by henry @{
            if (contractSignRt != null && contractSignRt.getId() != null) {
            	contractSignRt = contractService.getContractSignRt(contractSignRt.getId());
                baseinfo = contractSignRt.getEmployeeinfoBase();
                if (contractSignRt.getBeginDate() != null){
                	contractSignRt.setBeginDateStr(DateUtil.getStrByDate(contractSignRt.getBeginDate(), "yyyy-MM-dd"));
                }
                if (contractSignRt.getEndDate() != null){
                    contractSignRt.setEndDateStr(DateUtil.getStrByDate(contractSignRt.getEndDate(), "yyyy-MM-dd"));
                }
            }
            if (contractSignRtt != null && contractSignRtt.getId() != null) {
            	contractSignRtt = contractService.getContractSignRtt(contractSignRtt.getId());
                baseinfo = contractSignRtt.getEmployeeinfoBase();
                if (contractSignRtt.getBeginDate() != null){
                	contractSignRtt.setBeginDateStr(DateUtil.getStrByDate(contractSignRtt.getBeginDate(), "yyyy-MM-dd"));
                }
                if (contractSignRtt.getEndDate() != null){
                	contractSignRtt.setEndDateStr(DateUtil.getStrByDate(contractSignRtt.getEndDate(), "yyyy-MM-dd"));
                }
            }
            // added by henry @}
        }
        ServletActionContext.getRequest().getSession().setAttribute("startTime", System.currentTimeMillis());
        version = contractService.getVersion(version.getId());
        if(StringUtils.equals("contract_template1", version.getContractTemplate())){//厦门公司合同
            return "sign_create";
        }else if(StringUtils.equals("contract_template2", version.getContractTemplate())){//樟州公司合同
            return "sign_create_zz";
        }else if(StringUtils.equals("contract_template3", version.getContractTemplate())){//厦门乔盛服装饰品有限公司退休合同
//        	if(contractSignRt == null){
//        		contractSignRt = new ContractSignRt();
//        		contractSignRt.setCompanyName("厦门乔盛服装饰品有限公司");
//        	}
            return "sign_create_rt";
        }else if(StringUtils.equals("contract_template4", version.getContractTemplate())){//漳州通茂服装饰品有限公司退休员工合同
//        	if(contractSignRtt == null){
//        		contractSignRtt = new ContractSignRtt();
//        		contractSignRtt.setCompanyName("漳州通茂服装饰品有限公司");
//        	}
            return "sign_create_rtt";
        }
        return "error";
    }

    @Action(value = "/ajax/contract_sign_add", results = {
            @Result(name = "success", type = "json", params = {"root", "totalTime"})
    })
    public String add() {
        contractSign.setCancel("0");
        contractSign.setState(1);
        if(reSignContractSignId != null && reSignContractSignId > 0){
            contractSign.setState(7);//已续签
        }
        if (contractSign.getId() != null && contractSign.getId() > 0) {          //edit
            Duty duty = dutyService.get(contractSign.getDuty().getId());
            contractSign.setDuty(duty);
            if(contractSign.getVersion() == null){
                contractSign.setVersion(version);
            }
            contractSign.setAuditStatus(AuditStatus.wait_audit);
            contractService.updateSignContract(contractSign);
        } else {
            if(version == null || version.getId() == null){
                return "error";
            }
            contractSign.setVersion(version);
            contractSign.setAuditStatus(AuditStatus.wait_audit);
            Duty duty = dutyService.get(contractSign.getDuty().getId());
            contractSign.setDuty(duty);
            contractService.saveSignContract(reSignContractSignId, contractSign);            //save
        }
        long start = (Long) ServletActionContext.getRequest().getSession().getAttribute("startTime");
        long end = System.currentTimeMillis();
        totalTime = DateUtil.getDiffDate(start, end);
        ServletActionContext.getRequest().getSession().removeAttribute("startTime");

        return SUCCESS;
    }

    @Action(value = "/ajax/contract_sign_zz_add", results = {
            @Result(name = "success", type = "json", params = {"root", "totalTime"})
    })
    public String addZz() {
        contractSignZz.setCancel("0");
        contractSignZz.setState(1);
        if(reSignContractSignZzId != null && reSignContractSignZzId > 0){
            contractSignZz.setState(7);//已续签
        }
        if(version == null || version.getId() == null){
            return "error";
        }
        contractSignZz.setVersion(version);
        if(StringUtils.equals(contractSignZz.getContractType(), "3")){
            contractSignZz.setSyqStartDate(DateUtil.createDate(getParameter("syqStartDate")));
            contractSignZz.setSyqEndDate(DateUtil.createDate(getParameter("syqEndDate")));
        }
        if (contractSignZz.getId() != null && contractSignZz.getId() > 0) {          //edit
            Duty duty = dutyService.get(contractSignZz.getDuty().getId());
            contractSignZz.setDuty(duty);
            ContractSignZz c = contractService.getContractSignZz(contractSignZz.getId());
            contractSignZz.setAuditStatus(c.getAuditStatus());
            contractSignZz.setCreate_date(c.getCreate_date());
            contractSignZz.setCreator_id(c.getCreator_id());
            contractService.updateSignContract(contractSignZz);
        } else {
            contractSignZz.setAuditStatus(AuditStatus.wait_audit);
            Duty duty = dutyService.get(contractSignZz.getDuty().getId());
            contractSignZz.setDuty(duty);
            contractService.saveSignContract(reSignContractSignZzId, contractSignZz);            //save
        }
        long start = (Long) ServletActionContext.getRequest().getSession().getAttribute("startTime");
        long end = System.currentTimeMillis();
        totalTime = DateUtil.getDiffDate(start, end);
        ServletActionContext.getRequest().getSession().removeAttribute("startTime");

        return SUCCESS;
    }

    @Action(value = "/ajax/contract_sign_rt_add", results = {
            @Result(name = "success", type = "json", params = {"root", "totalTime"})
    })
    public String addRt() {
    	Long dutyId = getParameter("contractSignRt.duty.id") == null ? -1 : Long.parseLong(getParameter("contractSignRt.duty.id"));
    	Long employeeId = getParameter("contractSignRt.employeeinfoBase.id") == null ? -1 : Long.parseLong(getParameter("contractSignRt.employeeinfoBase.id"));
    	if(contractSignRt.getEmployeeinfoBase() == null){
    		contractSignRt.setEmployeeinfoBase(employeeService.getEmployeeinfoBase(employeeId));
    	}
        contractSignRt.setCancel("0");
        contractSignRt.setState(1);
        if(reSignContractSignRtId != null && reSignContractSignRtId > 0){
            contractSignRt.setState(7);//已续签
        }
        if(version == null || version.getId() == null){
            return "error";
        }
        contractSignRt.setVersion(version);
        if (contractSignRt.getId() != null && contractSignRt.getId() > 0) {          //edit
        	if(dutyId > 0){
        		Duty duty = dutyService.get(dutyId);
            	contractSignRt.setDuty(duty);
        	}
            //ContractSignRt c = contractService.getContractSignRt(contractSignRt.getId());
            //contractSignRt.setAuditStatus(c.getAuditStatus());
//            contractSignRt.setCreate_date(c.getCreate_date());
//            contractSignRt.setCreator_id(c.getCreator_id());
        	contractSignRt.setAuditStatus(AuditStatus.wait_audit);
            contractService.updateSignContract(contractSignRt);
        } else {
            contractSignRt.setAuditStatus(AuditStatus.wait_audit);
            if(dutyId > 0){
            	Duty duty = dutyService.get(dutyId);
            	contractSignRt.setDuty(duty);
            }
            contractService.saveSignContract(reSignContractSignRtId, contractSignRt);            //save
        }
        long start = (Long) ServletActionContext.getRequest().getSession().getAttribute("startTime");
        long end = System.currentTimeMillis();
        totalTime = DateUtil.getDiffDate(start, end);
        ServletActionContext.getRequest().getSession().removeAttribute("startTime");

        return SUCCESS;
    }

    @Action(value = "/ajax/contract_sign_rtt_add", results = {
            @Result(name = "success", type = "json", params = {"root", "totalTime"})
    })
    public String addRtt() {
    	Long dutyId = getParameter("contractSignRtt.duty.id") == null ? -1 : Long.parseLong(getParameter("contractSignRtt.duty.id"));
    	Long employeeId = getParameter("contractSignRtt.employeeinfoBase.id") == null ? -1 : Long.parseLong(getParameter("contractSignRtt.employeeinfoBase.id"));
    	if(contractSignRtt.getEmployeeinfoBase() == null){
    		contractSignRtt.setEmployeeinfoBase(employeeService.getEmployeeinfoBase(employeeId));
    	}
    	contractSignRtt.setCancel("0");
    	contractSignRtt.setState(1);
        if(reSignContractSignRttId != null && reSignContractSignRttId > 0){
            contractSignRtt.setState(7);//已续签
        }
        if(version == null || version.getId() == null){
            return "error";
        }
        contractSignRtt.setVersion(version);
        if (contractSignRtt.getId() != null && contractSignRtt.getId() > 0) {          //edit
        	if(dutyId > 0){
        		Duty duty = dutyService.get(dutyId);
        		contractSignRtt.setDuty(duty);
        	}
//            ContractSignRtt c = contractService.getContractSignRtt(contractSignRtt.getId());
//            contractSignRtt.setAuditStatus(c.getAuditStatus());
//            contractSignRtt.setCreate_date(c.getCreate_date());
//            contractSignRtt.setCreator_id(c.getCreator_id());
        	contractSignRtt.setAuditStatus(AuditStatus.wait_audit);
            contractService.updateSignContract(contractSignRtt);
        } else {
            contractSignRtt.setAuditStatus(AuditStatus.wait_audit);
            if(dutyId > 0){
            	Duty duty = dutyService.get(dutyId);
            	contractSignRtt.setDuty(duty);
            }
            contractService.saveSignContract(reSignContractSignRttId, contractSignRtt);            //save
        }
        long start = (Long) ServletActionContext.getRequest().getSession().getAttribute("startTime");
        long end = System.currentTimeMillis();
        totalTime = DateUtil.getDiffDate(start, end);
        ServletActionContext.getRequest().getSession().removeAttribute("startTime");

        return SUCCESS;
    }

    @Action(value = "/contract/signContract", results = {@Result(name = "success", type = "json")})
    public String signContractState() throws Exception {                      //确认合同签署状态
        contractService.updateContractSignState(id, state);
        return SUCCESS;
    }


    public LimitedList<ContractSignPojo> getContractSignPojos() {
        return contractSignPojos;
    }

    public void setContractSignPojos(LimitedList<ContractSignPojo> contractSignPojos) {
        this.contractSignPojos = contractSignPojos;
    }

    public ContractSignPojo getSignPojo() {
        return signPojo;
    }

    public void setSignPojo(ContractSignPojo signPojo) {
        this.signPojo = signPojo;
    }

    public ContractSign getContractSign() {
        return contractSign;
    }

    public void setContractSign(ContractSign contractSign) {
        this.contractSign = contractSign;
    }

    public ContractSignZz getContractSignZz() {
        return contractSignZz;
    }

    public void setContractSignZz(ContractSignZz contractSignZz) {
        this.contractSignZz = contractSignZz;
    }
    
    public ContractSignRt getContractSignRt() {
		return contractSignRt;
	}
    
    public void setContractSignRt(ContractSignRt contractSignRt) {
		this.contractSignRt = contractSignRt;
	}

    public ContractSignRtt getContractSignRtt() {
        return contractSignRtt;
    }

    public void setContractSignRtt(ContractSignRtt contractSignRtt) {
        this.contractSignRtt = contractSignRtt;
    }

    public String getTotalTime() {
        return totalTime;
    }

    public void setTotalTime(String totalTime) {
        this.totalTime = totalTime;
    }

    public List<List<ContractSignAuditing>> getAudits() {
        return audits;
    }

    public void setAudits(List<List<ContractSignAuditing>> audits) {
        this.audits = audits;
    }

    public Duty getDuty() {
        return duty;
    }

    public void setDuty(Duty duty) {
        this.duty = duty;
    }

    public EmployeeinfoBase getBaseinfo() {
        return baseinfo;
    }

    public void setBaseinfo(EmployeeinfoBase baseinfo) {
        this.baseinfo = baseinfo;
    }

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public Integer getState() {
        return state;
    }

    public void setState(Integer state) {
        this.state = state;
    }

    public ContractVersion getVersion() {
        return version;
    }

    public void setVersion(ContractVersion version) {
        this.version = version;
    }

    public ContractSignPojo2 getSignPojo2() {
        return signPojo2;
    }

    public LimitedList<ContractSignPojo2> getPojo2s() {
        return pojo2s;
    }

    public String getType() {
        return type;
    }

    public void setType(String type) {
        this.type = type;
    }

    public Long getReSignContractSignId() {
        return reSignContractSignId;
    }

    public void setReSignContractSignId(Long reSignContractSignId) {
        this.reSignContractSignId = reSignContractSignId;
    }

    public Long getReSignContractSignZzId() {
        return reSignContractSignZzId;
    }

    public void setReSignContractSignZzId(Long reSignContractSignZzId) {
        this.reSignContractSignZzId = reSignContractSignZzId;
    }
    
    public Long getReSignContractSignRtId() {
		return reSignContractSignRtId;
	}
    
    public void setReSignContractSignRtId(Long reSignContractSignRtId) {
		this.reSignContractSignRtId = reSignContractSignRtId;
	}

    public boolean isResult() {
        return result;
    }

}
